package t20211225;

import java.util.LinkedList;

/**
 * @Author: DengJia
 * @Date: 2021/12/25 14:43
 * @Description:
 */

public class LearnLinkedList {
    public static void main(String[] args) {
        LinkedList<Integer> list = new LinkedList<Integer>() {{
            add(6);
            add(7);
            add(8);
            add(9);
        }};
        System.out.println("list.getFirst() = " + list.getFirst());
        System.out.println("list.element() = " + list.element());
        // 检索但不删除此列表的头部（第一个元素）。
        System.out.println("list.peek() = " + list.peek());

        LinkedList<Integer> list1 = new LinkedList<Integer>() {{
        }};
        // NoSuchElementException
        // System.out.println("list1.getFirst() = " + list1.getFirst());

        // NoSuchElementException
        // System.out.println("list1.element() = " + list1.element());

        // = null
        System.out.println("list1.peek() = " + list1.peek());

        // NoSuchElementException
        // list1.remove();

        // NoSuchElementException
        // list1.removeFirst();

        // = null
        System.out.println("list1.poll() = " + list1.poll());

        // 检索并删除此列表的头部（第一个元素）。
        System.out.println("list.poll() = " + list.poll());
        System.out.println("list = " + list);

        list.offer(8);
        System.out.println("list = " + list);

    }
}
